<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/pages/admin/common/header.jsp"%>
</head>
<body>
 !请务必检查所有required:true,是否符合业务逻辑
    <div class="easyui-panel" style="padding:5px;" title="查询">
         <form id="queryFm">
             <table>
        <#list modelColumns as column>
        <#if column_index%4 == 0>
       <tr>
        </#if>
        <#if column.type=="Date" || column.type=="BigDecimal">
                <td>
				${column.comment}大于等于：
                </td>
                 <td>
				<input <#if column.isCombobox=="1" >class="easyui-combobox" <#elseif column.type=="Date" >class="easyui-datetimebox" <#else>class="easyui-textbox" </#if> id="${column.name}" name="${column.name}" />
                 </td>
                 <td>
				${column.comment}小于等于：
                 </td>
                 <td>
				<input <#if column.isCombobox=="1" >class="easyui-combobox" <#elseif column.type=="Date" >class="easyui-datetimebox" <#else>class="easyui-textbox" </#if> id="${column.name}" name="${column.name}" />
                 </td>
         <#else>
                  <td>
				${column.comment}：
                  </td>
                  <td>
				<input <#if column.isCombobox=="1" >class="easyui-combobox" <#else>class="easyui-textbox" </#if> id="${column.name}" name="${column.name}" />
                  </td>
		</#if>
        <#if (column_index-3)%4 == 0>
        	</tr>
        </#if>			
		</#list>
			</table>
		</form>
		<br>
		<a href="#" class="easyui-linkbutton" id="queryBtn"
			data-options="iconCls:'icon-search'" onclick="query('#queryFm', '/admin/${modelName?uncap_first}/query', '#dg')">查询</a>
	</div>

	<table id="dg" class="easyui-datagrid" title="${modelComment !}管理"
		style="width:auto;height:auto"
		data-options="rownumbers:true, remoteSort:true,
			singleSelect:false, pagination:true, toolbar: '#tb',
			selectOnCheck:true, checkOnSelect:true">
		<thead>
			<tr>
				<th data-options="field:'ck',checkbox:true"></th>
               <#list modelColumns as column>
				<th data-options="field:'${column.name}',align:'center',sortable:true <#if column.type=="Date" >,formatter:timeFormatter</#if><#if column.isCombobox=="1" >,formatter:${column.name}Formatter</#if>">${column.comment}</th>
               </#list>
			</tr>
		</thead>
	</table>

	<div id="tb" style="height:auto">
		<a href="javascript:void(0)" class="easyui-linkbutton"
			data-options="iconCls:'icon-add',plain:false" onclick="add()">添加</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" 
			data-options="iconCls:'icon-cancel',plain:false" onclick="doDelete()">删除</a>
		<a href="javascript:void(0)" class="easyui-linkbutton"
			data-options="iconCls:'icon-edit',plain:false" onclick="update()">修改</a>
	</div>
	
	<div id="edit" class="easyui-window" title="修改${modelComment !}信息"
		style="width:auto;height:auto;"
		data-options="closed:true, modal:true, minimizable:false">
		<form id="fm">
			<table
				style="margin-left:20px;margin-right: 20px;margin-top: 20px;margin-bottom: 20px">
				<#list modelColumns as column>
				<tr <#if column.name == "id">style="visibility:hidden"</#if>>
					<td><#if column.isNullable == "NO"><span style="color:red">*</span></#if>${column.comment}</td>
					<td>
						<input <#if column.isCombobox == "1">class="easyui-combobox"<#elseif column.type=="Date">class="easyui-datetimebox"<#else>class="easyui-textbox" <#if column.name == "password">type="password" <#else>type="text"</#if></#if> id="${column.name}" 
						 name="${column.name}" <#if column.name == "id"> readonly="readonly"</#if> <#if column.isNullable == "NO" && column.isCombobox == "0">data-options="required:true"<#elseif column.isCombobox == "1" && column.isNullable == "YES">data-options="editable:false, panelHeight:'auto'"<#elseif column.isCombobox == "1" && column.isNullable == "NO">data-options="required:true, editable:false, panelHeight:'auto'"</#if>>
						<#if column.name == "password">
						<span style="color:red">*修改时不填使用原密码</span>
						</#if>
					</td>
				</tr>
				</#list>
			</table>
		</form>
		<a href="javascript:submitForm('#fm','/admin/${modelName?uncap_first}/' + operate, '#dg');" 
			class="easyui-linkbutton" data-options="iconCls:'icon-add'" >提交</a>
	</div>
	<%@ include file="/WEB-INF/pages/admin/common/metaJs.jsp"%>
	<script>
	
		var operate = null;
	
		$(function() {
		<#list modelColumns as column>
		<#if column.isCombobox == "1" && column.codeName != "NULL">
			initCodeCombobox("#${column.name}", "${column.codeName}");
		</#if>
		</#list>
			$("#queryBtn").trigger("click");
		});

		function add() {
			operate = "add";
			$("#fm").form("clear");
			
			$("#edit").window("center");
			$("#edit").window("open");
		}

		function update() {
			if(!isSelectedSingle("#dg")){
				return;
			}
			operate = "update";
			$("#fm").form("clear");
			$("#fm").form("load", $("#dg").datagrid("getSelected"));
			
		<#list modelColumns as column>
		<#if column.name == "password">
		        $("#password").textbox("setValue", "");
		</#if>
		</#list>
			
			
			$("#edit").window("center");
			$("#edit").window("open");
		}

		function doDelete() {
			if(!hasSelected("#dg")){
				return;
			}
			var ids = getSelections("#dg");
			ajaxAndAlert("/admin/${modelName?uncap_first}/delete", {ids:ids}, "#dg");
		}
		
		<#list modelColumns as column>
		<#if column.isCombobox == "1" && column.codeName != "NULL">
		
		function ${column.name}Formatter(val){
			return getCodeName(val, "${column.codeName}");
		}
		</#if>
		</#list>

	</script>
</body>
</html>